package com.yonyou.isv.demo.openapi.event.order;

import com.alibaba.fastjson.JSON;
import com.google.common.collect.Sets;
import com.yonyou.isv.demo.openapi.base.module.isv.event.ISVEventListener;
import com.yonyou.isv.demo.openapi.base.network.cryptor.EncryptionHolder;
import com.yonyou.isv.demo.openapi.event.IsvEventExtendType;
import com.yonyou.isv.demo.openapi.pojo.ISVOrderAuthBo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * @description: 订单事件
 * @author: nishch
 * @create: 2021-07-05
 **/
@Slf4j
@Component
@RequiredArgsConstructor
public class OrderEvent implements ISVEventListener<ISVOrderAuthBo> {

    /**
     * TODO:在这里写订单的处理逻辑
     * @param type 事项类型
     * @param event 解析后对象
     * @param holder 响应消息体
     * @return boolean
     */
    @Override
    public boolean onEvent(String type, ISVOrderAuthBo event, EncryptionHolder holder) {
        String jsonString = JSON.toJSONString(event);
        if (StringUtils.isNotBlank(jsonString)){
            log.info("order id: {}", jsonString);
            return true;
        }
        return false;
    }

    @Override
    public int priority() {
        return ISVEventListener.super.priority()-100;
    }

    @Override
    public Set<String> supportTypes() {
        return Sets.newHashSet(IsvEventExtendType.SUITE_AUTH);
    }

    @Override
    public Class<ISVOrderAuthBo> getEventClass() {
        return ISVOrderAuthBo.class;
    }

}
